<?php
/**
 * 默认装配项
 */
class Register
{
	/**
	 * 数据库实例
	 */
	public static function getDb()
	{
		return new Db(\SF\Config::get('db'));
	}


	/**
	 * Memcache实例
	 */
	public static function getMemcached()
	{
		return self::setCache('memcached');
	}


	/**
	 * 设置缓存
	 */
	protected static function setCache($name)
	{
		$config = Registry::get('config');
		$name = strtolower($name);
		$classFile = ROOT_PATH .'/libs/sf/cache/'. $name .'.class.php';
		$className = 'Cache_'. ucfirst($name);
		if (!is_file($classFile)) {
			require_once ROOT_PATH .'/libs/sf/exception.class.php';
			throw new Sf_Exception('指定的缓存类不存在');
		}
		require_once $classFile;
		return new $className($config[$name]);
	}
}